#include<etcd/Client.hpp>
#include<etcd/KeepAlive.hpp>
#include<etcd/Response.hpp>
#include<etcd/SyncClient.hpp>
#include<etcd/Value.hpp>
#include<etcd/Watcher.hpp>
#include<iostream>

int main(int argc,char*argv[]){
    std::string etcd_host="http://127.0.0.1:2379";//etcd服务器地址信息
    //实例化客户端对象
    etcd::Client client(etcd_host);
    //创建并获取一个租约保活对象---指定租约有效时长
    auto keep_alive=client.leasekeepalive(3).get();//租约有效时长设置为3秒，阻塞获取响应
    //获取租约id
    auto lease_id=keep_alive->Lease();
    //向etcd添加数据
    auto resp1=client.add("/server/user","127.0.0.1:8080",lease_id).get();//添加一个用户服务，设置公约
    if(resp1.is_ok()==false){
        std::cout<<"数据添加失败: "<<resp1.error_message()<<std::endl;
        return -1;
    }
    auto resp2=client.add("/server/friend","127.0.0.1:8888").get();//添加一个用户服务，设置公约
    if(resp2.is_ok()==false){
        std::cout<<"数据添加失败: "<<resp2.error_message()<<std::endl;
        return -1;
    }

    std::this_thread::sleep_for(std::chrono::seconds(10));
    return 0;
}